package cn.edu.scau.cmi.huangxiaodong.exercise10;

public class EncryptAndDecrypt {

	String encrypt(String source, String password) {
		char[] p = password.toCharArray();
		int n = p.length;
		char[] c = source.toCharArray();
		int m = c.length;
		for (int k = 0; k < m; k++) {
			int mm = c[k] + p[k % n];
			c[k] = (char)mm;
		}
		return new String(c);
	}
	
	String decrypt(String source, String password) {
		char[] p = password.toCharArray();
		int n = p.length;
		char[] c = source.toCharArray();
		int m = c.length;
		for (int k = 0; k < m; k++) {
			int mm = c[k] - p[k % n];
			c[k] = (char)mm;
		}
		return new String(c);
	}
}